package forum.server.persistence;



import org.junit.Test;

import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;

import forum.server.domain.LoggedInUser;

public class ConnectedUsersTest {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}
	
	@Test
	public void testConnectedUsers(){
		try {

            DataManipulatorInt instance = DataManipulatorProxy.getInstance();
            instance.resetDataBase();
            System.out.println("Starting the test...");
            System.out.println("the current guests count: " + instance.getGuestCount());
            instance.incGuestCount();
            instance.incGuestCount();
            instance.incGuestCount();
            System.out.println("the current guests count: " + instance.getGuestCount());
            instance.decGuestCount();      
            System.out.println("the current guests count: " + instance.getGuestCount());
            
            instance.addUser(new LoggedInUser("nrp", "1234"));//without the security algo
            instance.connectUser("nrp");
            assertTrue(instance.getConnectedRegisteredUsers().get(0).equals("nrp"));
            instance.disconnectUser("nrp");
            assertEquals(instance.getConnectedRegisteredUsers().size(), 0);
           
            /*ClientMessage message=new ViewForumMessage();
            ForumFacadeInt f=new ForumFacade();
            ServerResponse response = message.doOperation(f);
            System.out.println(response.getResponse());
            //DataManipulatorInt instance = new HibernateSqlDataManipulator();
           
            System.out.println("number of users:"+instance.countUsers());
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        session.save(new Moderator("moderator1","1234"));
        session.save(new Moderator("moderator2","1234"));
        session.save(new Moderator("moderator3","1234"));
        session.save(new Moderator("moderator4","1234"));
        session.save(new LoggedInUser("mosdfkjhb4","1234"));
        session.save(new LoggedInUser("modesjbkasdjfb.kjbr4","1234"));
        session.save(new LoggedInUser("modesjllaYHFUSDNor4","1234"));
        session.getTransaction().commit();
        System.out.println("number of users:"+instance.countUsers());
        Vector<LoggedInUser> users=instance.getAllUsersForPromotion();
        for(LoggedInUser u:users)
            System.out.println(u.getUsername());
        System.out.println("\n\n\n");
        instance.addPost(new Post(instance.generateNewPostId()));
        Post p1=new Post("yoo", "yoo2", new PostContent("yoo Post content"), instance.generateNewPostId());
        instance.addPost(p1);
        instance.addPost(new Post(instance.generateNewPostId()));
        instance.addReply(p1.getPostId(), new Post(instance.generateNewPostId()));
        instance.modifyPost(p1.getPostId(), new PostContent("the modified post content"));
        p1=instance.getPost(p1.getPostId());
        System.out.println("new content: "+p1.getAuthor()+" "+p1.getContent());*/
       
    }
    catch (Exception e) {
            e.printStackTrace();
            fail("No exception should be thrown.");
    }
	}
}
